//
//  addbaojiaViewController.m
//  HAODE
//
//  Created by panquanReabam.com on 15/9/18.
//  Copyright (c) 2015年 reabam.com. All rights reserved.
//
#import "addProductViewController.h"

#import "HAODEsingleton.h"
#import "HttpRequest.h"
#import "RDVTabBarController.h"
#import "UIViewExt.h"
#import "ProductView.h"
#import "ZJSwitch.h"
#import "addguigeCell.h"
#import "VPImageCropperViewController.h"
#import "UpYun.h"
#import "PlatformProductTypeListViewController.h"
#import "SelectTag_NewViewController.h"
@interface addProductViewController ()<UICollectionViewDataSource,UICollectionViewDelegate,UIActionSheetDelegate, UICollectionViewDelegateFlowLayout,UIImagePickerControllerDelegate,UINavigationControllerDelegate,UIGestureRecognizerDelegate,UITextFieldDelegate,UITextViewDelegate>
{
    NSMutableArray *imageArray;
    HAODEsingleton *commdity;
    UIButton*Btn;
    UITextField*leibieTextFied;
    UITextField*mingchengTextFied;
    UITextField*kucunTextFied;
    UITextView*tv;
    UIImageView*imagess;
    UITextField*jiageTextFied;
    UIView*myToolBar;
    UIScrollView*myscrollView;
    UIView*view2;
    UIView*view1;
    UIView*view;
    UIView*biaoqianview;
     ProductView *clothView;
    NSMutableArray* arrrs;
    NSMutableArray *selectFeatureCodeArray;
    NSMutableArray *specName;
    NSMutableArray *specPrice;
    NSMutableArray *specInv;
    BOOL saveAccount;
    UIView*guigeview;
    UIView*guigeviews;
    int pageNumber;
    UIButton*shanchuBtn;
    UIButton* tianjiashanping;
    UILabel* jiage;
    UILabel* kucun;
    UIView*view33;
     NSMutableArray*imageList;
    UILabel*label;
    ZJSwitch*switch2;
    UIView * view22;
    NSString*isOpen;
    UIView*vi;
    UILabel* biaoqianshu;
}
@end

@implementation addProductViewController
@synthesize alt = alt;
- (void)viewDidDisappear:(BOOL)animated

{
    
    [super viewDidDisappear:animated];
 
    self.navigationController.delegate = nil;
    
}
-(void)BackAction:(UIButton *)sender{
    
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    self.navigationController.delegate = self;
    
    self.navigationController.interactivePopGestureRecognizer.delegate = self;
    
    
    [[self rdv_tabBarController] setTabBarHidden:YES];
    self.navigationController.navigationBarHidden = NO;
        self.navigationController.navigationBar.barStyle = UIBaselineAdjustmentNone;
    UILabel *lineLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 43,ScreenWidth, 1)];
    [lineLabel setBackgroundColor:[UIColor colorWithRed:238.0/255.0 green:238.0/255.0 blue:238.0/255.0 alpha:1.0]];
    [self.navigationController.navigationBar addSubview:lineLabel];
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    [[UINavigationBar appearance] setBarTintColor:Color];
    
    UIImage* backImage = [UIImage imageNamed:@"fanhui"];
    CGRect backframe = CGRectMake(0,0,30,30);
    UIButton* backButton= [[UIButton alloc] initWithFrame:backframe];
    [backButton setBackgroundImage:backImage forState:UIControlStateNormal];
    backButton.titleLabel.textAlignment=NSTextAlignmentLeft;
    [backButton addTarget:self action:@selector(BackAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    self.navigationItem.leftBarButtonItem = leftBarButtonItem;
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@""] forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage =[[UIImage alloc] init];
    
    
    leibieTextFied.text=commdity.content;
    
    
    NSLog(@"=======%@",commdity.selectTagNameArray);
    if (commdity.selectTagCodeArray.count>0) {
        
        biaoqianshu.text=[NSString stringWithFormat:@"(已选择%ld个标签)", commdity.selectTagCodeArray.count];
        biaoqianshu.textColor=shenhongsecolor;
        [vi removeFromSuperview];
        
        vi=[[UIView alloc]initWithFrame:CGRectMake(0, 44+10, ScreenWidth, 300)];
        [biaoqianview addSubview:vi];
        for (int i = 0,j = 0; i < commdity.selectTagCodeArray.count; i++) {
            if (i % 4 == 0) {
                j++;
            }
            
            clothView = [[ProductView alloc]initWithFrame:CGRectMake(12.5+(ScreenWidth/4-5)*(i%4), (35*j), ScreenWidth/4-15, 26)];
            clothView.buttonView.titleLabel.textAlignment=NSTextAlignmentCenter;
            clothView.buttonView.titleLabel.font=[UIFont systemFontOfSize:conten14fot];
            [clothView.buttonView setTitle: [commdity.selectTagNameArray objectAtIndex:i]  forState:UIControlStateNormal];
            CGColorSpaceRef colorSpace2 = CGColorSpaceCreateDeviceRGB();
            CGColorRef colorref2 = CGColorCreate(colorSpace2,(CGFloat[]){209/255.0,170/255.0, 56/255.0, 1.0   });
            clothView.buttonView.backgroundColor=[UIColor colorWithRed:255/255.0 green:255/255.0 blue:234/255.0 alpha:1];
            [clothView.buttonView.layer setBorderColor:colorref2];//边框颜色
            
            [clothView.buttonView setTitleColor:huangtitleColor forState:0];
            [vi addSubview:clothView];
            
        }
        UIView*huiseview=[[UIView alloc]initWithFrame:CGRectMake(0,clothView.bottom+20, ScreenWidth, 10)];
        huiseview.backgroundColor=zuiqianhuicolor;
        huiseview.layer.borderWidth = 0.35;
        huiseview.layer.borderColor = qianhuicolor.CGColor;
        [vi addSubview:huiseview];

        tv=[[UITextView alloc]init];
        tv.frame=CGRectMake(15, clothView.bottom+40, ScreenWidth-30, ScreenHeight*185/1334);
        tv.backgroundColor = [UIColor whiteColor];//设置它的背景颜色/Users/jiezsoft/Desktop/
        tv.scrollEnabled = YES;//是否可以拖动
        tv.delegate=self;
        //                tv.autoresizingMask = UIViewAutoresizingFlexibleHeight;//自适应高
        tv.font = [UIFont fontWithName:@"Arial" size:15.0];//设置字体名字和字体大小
        tv.layer.borderWidth =0;
        CGColorSpaceRef registedSpace11 = CGColorSpaceCreateDeviceRGB();
        CGColorRef tureBTncolorref111 = CGColorCreate(registedSpace11,(CGFloat[]){ 0, 0, 0, 0.3 });
        //                tv.keyboardType = UIKeyboardTypePhonePad;
        [tv.layer setBorderColor:tureBTncolorref111];//边框颜色
        tv.layer.cornerRadius =0;
        [vi addSubview:tv];
        
        
        
        imagess=[[UIImageView alloc]initWithFrame:CGRectMake(10, 8, 51/3, 43/3)];
        imagess.image=[UIImage imageNamed:@"_0000_xingxifankui.png"];
        [tv addSubview:imagess];
        label=[[UILabel alloc]init];
        label.frame =CGRectMake(33, 8, ScreenWidth-60, 15);
        label.text = @"详情描述";
        label.textColor=zuiqianhuicolor;
        label.numberOfLines=0;
        label.font=[UIFont systemFontOfSize:15];
        label.enabled = NO;//lable必须设置为不可用
        label.backgroundColor = [UIColor clearColor];
        [tv addSubview:label];
        
        myToolBar=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, viewheight)];
        myToolBar.backgroundColor=jianpancolor;
        UIButton*  tubtnDone=[[UIButton alloc]initWithFrame:CGRectMake(logoX,logoY, logoheight, logowidth)];
        [tubtnDone setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
        [tubtnDone addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
        [myToolBar addSubview:tubtnDone];
        UIButton*btnDone111=[[UIButton alloc]initWithFrame:CGRectMake(myToolBar.frame.size.width - 55, 12, 40, 16)];
        [btnDone111 setTitle:@"确定" forState:UIControlStateNormal];
        [btnDone111 setTitleColor:jianpancolor1 forState:UIControlStateNormal];
        btnDone111 .titleLabel .font=[UIFont systemFontOfSize:daxiao];
        [btnDone111 addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
        [myToolBar addSubview:btnDone111];
        myToolBar.alpha=alp;
        UIButton* dabtn=[[UIButton alloc]initWithFrame:CGRectMake(myToolBar.frame.size.width-60, 0, 60, 40)];
        [dabtn addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
        [myToolBar addSubview:dabtn];
        
        
        tv.inputAccessoryView = myToolBar;
        
        
    }else{
        biaoqianshu.text=[NSString stringWithFormat:@"%@", @"(请选择标签)"];
        biaoqianshu.font=[UIFont systemFontOfSize:conten14fot];
        biaoqianshu.textColor=qianhuicolor;
        [vi removeFromSuperview];
        
        vi=[[UIView alloc]initWithFrame:CGRectMake(0, 44+10, ScreenWidth, 300)];
        
        [biaoqianview addSubview:vi];
       
        
        UIView*huiseview=[[UIView alloc]initWithFrame:CGRectMake(0,0, ScreenWidth, 10)];
        huiseview.backgroundColor=zuiqianhuicolor;
        huiseview.layer.borderWidth = 0.35;
        huiseview.layer.borderColor = qianhuicolor.CGColor;
        [vi addSubview:huiseview];
        tv=[[UITextView alloc]init];
        tv.frame=CGRectMake(15, 40, ScreenWidth-30, ScreenHeight*185/1334);
        tv.backgroundColor = [UIColor whiteColor];//设置它的背景颜色/Users/jiezsoft/Desktop/
        tv.scrollEnabled = YES;//是否可以拖动
        tv.delegate=self;
        //                tv.autoresizingMask = UIViewAutoresizingFlexibleHeight;//自适应高
        tv.font = [UIFont fontWithName:@"Arial" size:15.0];//设置字体名字和字体大小
        tv.layer.borderWidth =0;
        CGColorSpaceRef registedSpace11 = CGColorSpaceCreateDeviceRGB();
        CGColorRef tureBTncolorref111 = CGColorCreate(registedSpace11,(CGFloat[]){ 0, 0, 0, 0.3 });
        //                tv.keyboardType = UIKeyboardTypePhonePad;
        [tv.layer setBorderColor:tureBTncolorref111];//边框颜色
        tv.layer.cornerRadius =0;
        [vi addSubview:tv];
        
        
        
        imagess=[[UIImageView alloc]initWithFrame:CGRectMake(10, 8, 51/3, 43/3)];
        imagess.image=[UIImage imageNamed:@"_0000_xingxifankui.png"];
        [tv addSubview:imagess];
        label=[[UILabel alloc]init];
        label.frame =CGRectMake(33, 8, ScreenWidth-60, 15);
        label.text = @"详情描述";
        label.textColor=zuiqianhuicolor;
        label.numberOfLines=0;
        label.font=[UIFont systemFontOfSize:15];
        label.enabled = NO;//lable必须设置为不可用
        label.backgroundColor = [UIColor clearColor];
        [tv addSubview:label];
        
        myToolBar=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, viewheight)];
        myToolBar.backgroundColor=jianpancolor;
        UIButton*  tubtnDone=[[UIButton alloc]initWithFrame:CGRectMake(logoX,logoY, logoheight, logowidth)];
        [tubtnDone setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
        [tubtnDone addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
        [myToolBar addSubview:tubtnDone];
        UIButton*btnDone111=[[UIButton alloc]initWithFrame:CGRectMake(myToolBar.frame.size.width - 55, 12, 40, 16)];
        [btnDone111 setTitle:@"确定" forState:UIControlStateNormal];
        [btnDone111 setTitleColor:jianpancolor1 forState:UIControlStateNormal];
        btnDone111 .titleLabel .font=[UIFont systemFontOfSize:daxiao];
        [btnDone111 addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
        [myToolBar addSubview:btnDone111];
        myToolBar.alpha=alp;
        UIButton* dabtn=[[UIButton alloc]initWithFrame:CGRectMake(myToolBar.frame.size.width-60, 0, 60, 40)];
        [dabtn addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
        [myToolBar addSubview:dabtn];
        
        
        tv.inputAccessoryView = myToolBar;
        
        
        
    }
 
    

}
-(void)viewDidLoad{
    
    [super viewDidLoad];
      isOpen=@"1";
    saveAccount =NO;
    NSUserDefaults *user11 = [NSUserDefaults standardUserDefaults];
    NSString* Token11 = [user11 objectForKey:@"tokenId"];
    NSMutableDictionary *params11 = [NSMutableDictionary new];
    [params11 setValue:Token11 forKey:@"tokenId"];
    [params11 setValue:@"product" forKey:@"uploadType"];
    
//    [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
    [HttpRequest requestData:@"Common/GetUpyunFormParams" params:params11 success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) {
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                [Global hideProgressHUDInternal:self.view];
                NSLog(@"%@",severDataDict.dataDict);
                
                NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
                NSString*policy=[severDataDict.dataDict objectForKey:@"policy"];
                NSString*signature=[severDataDict.dataDict objectForKey:@"signature"];
                NSString*action=[severDataDict.dataDict objectForKey:@"action"];
                [user setObject:signature forKey:@"signature"];
                [user setObject:policy forKey:@"policy"];
                [user setObject:action forKey:@"action"];
                [user synchronize];
                
            }else{
                [Global hideProgressHUDInternal:self.view];
                NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                // [Global showTextHud:requestResultStr view:self.view];
                [Global showTextHudSub:requestResultStr view:self.view];
            }
            
        }
        else
        {
            [Global hideProgressHUDInternal:self.view];
            
            [Global showTextHudSub:@"连接失败" view:self.view];
        }
        
    }];

    commdity=[HAODEsingleton shared];
    _table.separatorStyle=UITableViewCellSeparatorStyleNone;
    selectFeatureCodeArray=[[NSMutableArray alloc]init];
    specName=[[NSMutableArray alloc]init];
    specInv=[[NSMutableArray alloc]init];
    specPrice=[[NSMutableArray alloc]init];
    imageList=[[NSMutableArray alloc]init];
    self.title = @"添加商品";
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                                     backColor,
                                                                     UITextAttributeTextColor,
                                                                     [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1],
                                                                     UITextAttributeTextShadowColor,
                                                                     [NSValue valueWithUIOffset:UIOffsetMake(0, 0)],
                                                                     UITextAttributeTextShadowOffset,
                                                                     [UIFont fontWithName:@"Helvetica Neue" size:tetlefot],
                                                                     UITextAttributeFont,nil]];
    
    
    myscrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0, ScreenWidth, 100)];
    [myscrollView setBackgroundColor: zuiqianhuicolor];
    
    myscrollView.delegate = self;
    myscrollView.userInteractionEnabled = YES;
    myscrollView.scrollEnabled = YES;
    myscrollView.showsVerticalScrollIndicator = FALSE;
    myscrollView.showsHorizontalScrollIndicator = FALSE;
    [self.view addSubview:myscrollView];
    imageArray = [NSMutableArray arrayWithObjects:nil];
    
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    //设置单元格的尺寸
    flowLayout.itemSize = CGSizeMake(collectionCellHeight, collectionCellHeight);
    
    flowLayout.minimumInteritemSpacing = 5;
    flowLayout.minimumLineSpacing = 5;
    flowLayout.sectionInset = UIEdgeInsetsMake(15, 15, 15, 15);
    
    _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0,10, ScreenWidth, collectionCellHeight+15*2) collectionViewLayout:flowLayout];
    _collectionView.backgroundColor = [UIColor whiteColor];
    self.collectionView.dataSource=self;
    self.collectionView.delegate=self;
    
    [self.collectionView registerClass:[webCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    [myscrollView addSubview:self.collectionView];
    
    
    UILabel *line1s = [[UILabel alloc]initWithFrame:CGRectMake(0,0, ScreenWidth, 0.35)];
    line1s.backgroundColor = labelColor;
    [self.collectionView addSubview:line1s];
    myToolBar=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, viewheight)];
    myToolBar.backgroundColor=jianpancolor;
    UIButton*  tubtnDone=[[UIButton alloc]initWithFrame:CGRectMake(logoX,logoY, logoheight, logowidth)];
    [tubtnDone setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    [tubtnDone addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:tubtnDone];
    UIButton*btnDone111=[[UIButton alloc]initWithFrame:CGRectMake(myToolBar.frame.size.width - 55, 12, 40, 16)];
    [btnDone111 setTitle:@"确定" forState:UIControlStateNormal];
    [btnDone111 setTitleColor:jianpancolor1 forState:UIControlStateNormal];
    btnDone111 .titleLabel .font=[UIFont systemFontOfSize:daxiao];
    [btnDone111 addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:btnDone111];
    myToolBar.alpha=alp;
    UIButton* dabtn=[[UIButton alloc]initWithFrame:CGRectMake(myToolBar.frame.size.width-60, 0, 60, 40)];
    [dabtn addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:dabtn];
    
    
    
    view22=[[UIView alloc]initWithFrame:CGRectMake(0, self.collectionView.bottom+10, ScreenWidth, 45)];
    view22.backgroundColor=[UIColor whiteColor];
    [myscrollView addSubview:view22];
    UILabel *lineLabe1=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 0.35)];
    lineLabe1.backgroundColor=qianhuicolor;
    [view22 addSubview:lineLabe1];
    UILabel* lingqu=[[UILabel alloc]initWithFrame:CGRectMake(15, 0, 200,45)];
    lingqu.text=[NSString stringWithFormat:@"%@", @"在平台商城中公开领取"];
    lingqu.font=[UIFont systemFontOfSize:conten14fot];
    lingqu.textColor=shenhuicolor;
    [view22 addSubview:lingqu];
    
    switch2 = [[ZJSwitch alloc] initWithFrame:CGRectMake(ScreenWidth-75, 7, 55, ScreenHeight*15/1334)];
    switch2.onTintColor =luseColor;
    switch2.on = YES;
    [switch2 addTarget:self action:@selector(switchAction1:) forControlEvents:UIControlEventValueChanged];
    [view22 addSubview:switch2];


    view1=[[UIView alloc]initWithFrame:CGRectMake(0, self.collectionView.bottom+10+45, ScreenWidth, 190-45)];
    view1.backgroundColor=[UIColor whiteColor];
    [myscrollView addSubview:view1];
    
    UILabel *line1 = [[UILabel alloc]initWithFrame:CGRectMake(15,0, ScreenWidth-30, 0.35)];
    line1.backgroundColor = qianhuicolor;
     [view1 addSubview:line1];
    UILabel *line11 = [[UILabel alloc]initWithFrame:CGRectMake(15,45, ScreenWidth-30, 0.35)];
    line11.backgroundColor = qianhuicolor;
    [view1 addSubview:line11];
    UILabel *line111 = [[UILabel alloc]initWithFrame:CGRectMake(15,90, ScreenWidth-30, 0.35)];
    line111.backgroundColor = qianhuicolor;
    [view1 addSubview:line111];
    UILabel *line1111 = [[UILabel alloc]initWithFrame:CGRectMake(0,135, ScreenWidth, 0.35)];
    line1111.backgroundColor = qianhuicolor;
    [view1 addSubview:line1111];

    UILabel* leibie=[[UILabel alloc]initWithFrame:CGRectMake(20, 0, ScreenWidth-50,45)];
    leibie.text=[NSString stringWithFormat:@"%@", @"类别"];
    leibie.font=[UIFont systemFontOfSize:conten14fot];
    leibie.textColor=[UIColor blackColor];
    [view1 addSubview:leibie];
    UIButton*jiantouBtn3 = [[UIButton alloc]init];
    jiantouBtn3.frame = CGRectMake(ScreenWidth-30,15,8, 13);
    [jiantouBtn3 setImage:[UIImage imageNamed:@"xiangzuo-.png"] forState:UIControlStateNormal];
    [view1 addSubview:jiantouBtn3];
    
    leibieTextFied=[[UITextField alloc]initWithFrame:CGRectMake(70,  0, ScreenWidth*500/750,  45)];
    leibieTextFied.borderStyle = UITextBorderStyleNone;
    leibieTextFied.font = [UIFont systemFontOfSize: conten14fot];
    leibieTextFied.textColor=[UIColor blackColor];
    leibieTextFied.autocapitalizationType = UITextAutocapitalizationTypeSentences;
    leibieTextFied.tag=5;
    leibieTextFied.placeholder = @"请选择类别"; //默认显示的字
    [leibieTextFied setUserInteractionEnabled:NO];
    leibieTextFied.clearButtonMode = UITextFieldViewModeWhileEditing;
    [view1 addSubview:leibieTextFied];
    UIButton*leibieBtn=[[UIButton alloc]initWithFrame:CGRectMake(70, 0, ScreenWidth, 45)];
    [leibieBtn addTarget:self action:@selector(leibieBtn:) forControlEvents:UIControlEventTouchUpInside];
    [view1 addSubview:leibieBtn];
    
    
    
    UILabel* mingcheng=[[UILabel alloc]initWithFrame:CGRectMake(20, 45, 70,45)];
    mingcheng.text=[NSString stringWithFormat:@"%@", @"名称"];
    mingcheng.font=[UIFont systemFontOfSize:conten14fot];
    mingcheng.textColor=[UIColor blackColor];
    [view1 addSubview:mingcheng];
    mingchengTextFied=[[UITextField alloc]initWithFrame:CGRectMake(70,  45, ScreenWidth*550/750,  45)];
    mingchengTextFied.borderStyle = UITextBorderStyleNone;
    mingchengTextFied.font = [UIFont systemFontOfSize: conten14fot];
    mingchengTextFied.textColor=[UIColor blackColor];
    mingchengTextFied.autocapitalizationType = UITextAutocapitalizationTypeSentences;
    mingchengTextFied.tag=6;
    mingchengTextFied.placeholder = @"请输入商品名称"; //默认显示的字
    [mingchengTextFied setUserInteractionEnabled:YES];
    mingchengTextFied.delegate = self;
    mingchengTextFied.clearButtonMode = UITextFieldViewModeWhileEditing;
    [view1 addSubview:mingchengTextFied];
    

    
    jiage=[[UILabel alloc]initWithFrame:CGRectMake(20, 90, 70,45)];
    jiage.text=[NSString stringWithFormat:@"%@", @"价格"];
    jiage.font=[UIFont systemFontOfSize:conten14fot];
    jiage.textColor=[UIColor blackColor];
    [view1 addSubview:jiage];
    jiageTextFied=[[UITextField alloc]initWithFrame:CGRectMake(70,  90, ScreenWidth*550/750,  45)];
    jiageTextFied.keyboardType = UIKeyboardTypeNumberPad;
    jiageTextFied.font = [UIFont systemFontOfSize: conten14fot];
    jiageTextFied.textColor=[UIColor blackColor];
    jiageTextFied.tag=7;
    jiageTextFied.placeholder = @"请输入价格"; //默认显示的字
    [jiageTextFied setUserInteractionEnabled:YES];
    jiageTextFied.delegate = self;
    jiageTextFied.clearButtonMode = UITextFieldViewModeWhileEditing;
    [view1 addSubview:jiageTextFied];
    
    
    
    
    view33=[[UIView alloc]initWithFrame:CGRectMake(0, 180-45, ScreenWidth, 10)];
    view33.backgroundColor=zuiqianhuicolor;
    [view1 addSubview:view33];
    
    myscrollView.frame=CGRectMake(0, 0, ScreenWidth, view1.bottom);
    myscrollView.contentSize = CGSizeMake(ScreenWidth,view1.bottom );
    _table.tableHeaderView=myscrollView;
    
    
    
    guigeview=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 400)];
    guigeview.backgroundColor=[UIColor whiteColor];
    _table.tableFooterView=guigeview;
    
    tianjiashanping=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth,45)];
   [tianjiashanping setTitle:[NSString stringWithFormat:@"     %@", @"＋  添加商品规格"] forState:UIControlStateNormal];
    tianjiashanping.titleLabel.font=[UIFont systemFontOfSize:16.0];
    tianjiashanping.layer.borderWidth = 0.30;
    tianjiashanping.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
    tianjiashanping.layer.borderColor = qianhuicolor.CGColor;
   [tianjiashanping addTarget:self action:@selector(adds:) forControlEvents:UIControlEventTouchUpInside];
    [tianjiashanping setTitleColor:luseColor forState:UIControlStateNormal];
    NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"    %@", @"＋  添加商品规格"]];
    
    [AttributedStr addAttribute:NSFontAttributeName
     
                          value:[UIFont systemFontOfSize:16.0]
     
                          range:NSMakeRange(0, 8)];
    
    [AttributedStr addAttribute:NSForegroundColorAttributeName
     
                          value:hongsecolor
     
                          range:NSMakeRange(0, 7)];
    
    
    tianjiashanping.titleLabel.attributedText = AttributedStr;
    [guigeview addSubview:tianjiashanping];
    
    
    
    

    biaoqianview=[[UIView alloc]initWithFrame:CGRectMake(0, 45, ScreenWidth, 400)];
    biaoqianview.backgroundColor=[UIColor whiteColor];
    [guigeview addSubview:biaoqianview];

    UIView*huiseview=[[UIView alloc]initWithFrame:CGRectMake(0,0, ScreenWidth, 10)];
    huiseview.backgroundColor=zuiqianhuicolor;
    huiseview.layer.borderWidth = 0.35;
    huiseview.layer.borderColor = qianhuicolor.CGColor;
    [biaoqianview addSubview:huiseview];
    
    
   
    UILabel* BirthDate1=[[UILabel alloc]initWithFrame:CGRectMake(20, 10, ScreenWidth*75/750,44)];
    BirthDate1.text=[NSString stringWithFormat:@"%@", @"标签"];
    BirthDate1.font=[UIFont systemFontOfSize:conten14fot];
    BirthDate1.textColor=[UIColor blackColor];
    [biaoqianview addSubview:BirthDate1];
    
    biaoqianshu=[[UILabel alloc]initWithFrame:CGRectMake(BirthDate1.right,  10, 170,44)];
    biaoqianshu.text=[NSString stringWithFormat:@"%@", @"(请选择标签)"];
    biaoqianshu.font=[UIFont systemFontOfSize:conten14fot];
    biaoqianshu.textColor=qianhuicolor;
    [biaoqianview addSubview:biaoqianshu];
    
    
    UIButton*biaoqiangBtn=[[UIButton alloc]initWithFrame:CGRectMake(BirthDate1.right-15, 10, ScreenWidth, 88/2)];
    [biaoqiangBtn addTarget:self action:@selector(biaoqiangBtn:) forControlEvents:UIControlEventTouchUpInside];
    [biaoqianview addSubview:biaoqiangBtn];
    UIButton*jiantou = [[UIButton alloc]init];
    jiantou.frame = CGRectMake(ScreenWidth-30,15+10,8, 13);
    [jiantou setImage:[UIImage imageNamed:@"xiangzuo-.png"] forState:UIControlStateNormal];
    [biaoqianview addSubview:jiantou];
    
    UIImageView *_xianview = [[UIImageView alloc]initWithFrame:CGRectMake(15,44+10, ScreenWidth-30, 0.5)];
    _xianview.image=[UIImage imageNamed:@"hengxian"];
    [biaoqianview addSubview:_xianview];
    
    

    
    UIButton* baocun= [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 44, 30)];
    [baocun setTitle:@"保存" forState:UIControlStateNormal];
    baocun.titleLabel.font=[UIFont systemFontOfSize:15];
    [baocun setTitleColor:luseColor forState:UIControlStateNormal];
    [baocun addTarget:self action:@selector(baocun:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* leftBarButton = [[UIBarButtonItem alloc] initWithCustomView:baocun];
    self.navigationItem.rightBarButtonItem = leftBarButton;

    
    jiageTextFied.inputAccessoryView = myToolBar;
    leibieTextFied.inputAccessoryView = myToolBar;
    mingchengTextFied.inputAccessoryView = myToolBar;
 
    kucunTextFied.inputAccessoryView = myToolBar;
    
    pageNumber=0;
}
-(void)biaoqiangBtn:(UIButton*)sender{
    
    
    
    SelectTag_NewViewController *detailViewController = [[SelectTag_NewViewController alloc] init];
    detailViewController.optionNameString=@"ProductTag";
    detailViewController.selectedTagCodeArray=commdity.selectTagCodeArray;
    [self.navigationController pushViewController:detailViewController animated:YES];
    
    
}

-(void)switchAction1:(UISwitch*)sender{
    
    if (sender.on ==YES) {
        
        isOpen=@"1";
        
        
    }
    
    if (sender.on == NO) {
        isOpen=@"0";
        
    }
}


//上传数据
-(void)baocun:(UIButton*)sender{
    [imageList removeAllObjects];
    [self  upToUpYun];
    
}


-(void)upToUpYun
{
    if ([leibieTextFied.text length] < 1)
    {
        [self showAlertMessage:@"请选择类别"];
    }
    else
    {
        
        if ([mingchengTextFied.text length] <1)
        {
            [self showAlertMessage:@"请输入商品名称"];
        }
        else{

    [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
    for (int i=0; i<imageArray.count; i++) {
        
        UIImage *portraitImg = [[UIImage alloc]init];
       
        portraitImg = [self imageByScalingToMaxSize:imageArray[i]];
        

        UpYun *uy = [[UpYun alloc] init];
        uy.successBlocker = ^(id data)
        {
            
            
            NSString *imageURL;
            NSString *imageWIDTH;
            NSString *imageHEIGHT;
            imageURL=[data objectForKey:@"url"];
            imageWIDTH=[data objectForKey:@"image-width"];
            imageHEIGHT=[data objectForKey:@"image-height"];
            NSMutableDictionary *upYunImageDict=[NSMutableDictionary dictionary];
            [upYunImageDict setObject:imageURL forKey:@"imageUrl"];
            [upYunImageDict setObject:imageWIDTH forKey:@"imageWidth"];
            [upYunImageDict setObject:imageHEIGHT forKey:@"imageHeight"];
            
            [imageList addObject:upYunImageDict];
            
            NSLog(@"--------－－－－%ld",imageList.count);
            NSLog(@"--------－－－－%ld",imageArray.count);
            if (imageList.count==imageArray.count) {
                
                [Global hideProgressHUDInternal:self.view];
                NSLog(@"--------－－－－%@",imageList);
                [self  baocunxia];
            }
            
        };
        uy.failBlocker = ^(NSError * error)
        {
            [Global hideProgressHUDInternal:self.view];
            
            UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"上传失败" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
            [alert show];
            NSLog(@"%@",error);
        };
        uy.progressBlocker = ^(CGFloat percent, long long requestDidSendBytes)
        {
            
        };
        
        [uy uploadFile:portraitImg saveKey:[self getSaveKey]];
        
      
        
    }}
    }
}
-(void)baocunxia{
    
    
    
    
    if ([leibieTextFied.text length] < 1)
    {
        [self showAlertMessage:@"请选择类别"];
    }
    else
    {
        
        if ([mingchengTextFied.text length] <1)
        {
            [self showAlertMessage:@"请输入商品名称"];
        }
        else{
            
            NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
            NSString* Token = [user objectForKey:@"tokenId"];
            NSMutableDictionary *params = [NSMutableDictionary new];
            
            [params setValue:Token forKey:@"tokenId"];
            [params setValue:@"A" forKey:@"editType"];
            [params setValue:mingchengTextFied.text forKey:@"itemName"];
            [params setValue:commdity.code forKey:@"itemTypeCode"];
            [params setValue:tv.text forKey:@"details"];
            [params setValue:imageList  forKey:@"imageList"];
            [params setValue:isOpen forKey:@"isOpen"];
            NSMutableArray *specList=[NSMutableArray array];
            for (int i=0; i<specName.count; i++) {
                
                NSMutableDictionary *dic = [NSMutableDictionary dictionary];
                NSString *codeStr = [specName objectAtIndex:i];
                NSString *specPrice1 = [specPrice objectAtIndex:i];
//              NSString *specInv1 = [specInv objectAtIndex:i];
               
                [dic setValue:codeStr forKey:@"specName"];
                [dic setValue:[NSString stringWithFormat:@"%.2f",  specPrice1.doubleValue]  forKey:@"specPrice"];
//              [dic setValue:[NSString stringWithFormat:@"%.2f",  specInv1.doubleValue]forKey:@"specInv"];
                [dic setValue:@"" forKey:@"specId"];
                [specList addObject:dic];
            }
            
            [params setValue:specList  forKey:@"specList"];
            
            if (specList.count>0) {
                
            }else{
                            [params setValue:jiageTextFied.text forKey:@"salePrice"];
                            [params setValue:kucunTextFied.text forKey:@"invQty"];
            }
            
            

            
            NSMutableArray *mDocumentLine=[NSMutableArray array];
            for (int i=0; i<commdity.selectTagCodeArray.count; i++) {
                
                NSMutableDictionary *dic = [NSMutableDictionary dictionary];
                NSString *codeStr = [commdity.selectTagCodeArray objectAtIndex:i];
                [dic setValue:codeStr forKey:@"code"];
                [mDocumentLine addObject:dic];
                
                
            }

            
            [params setValue:mDocumentLine  forKey:@"tagList"];
            
            NSLog(@"33333333====%@",params);
            [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:20 view:self.view];
            
            [HttpRequest requestData:@"Product/SaveProduct" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
                if (isSuccess) {
                    
                    
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                        [Global hideProgressHUDInternal:self.view];
                        NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                        [Global showTextHudSub:requestResultStr view:self.view];
                        [self.navigationController popViewControllerAnimated:YES];
                        
//                        commdity.Dictss=nil;
                    }else{
                        [Global hideProgressHUDInternal:self.view];
                        NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                        [Global showTextHudSub:requestResultStr view:self.view];
                    }
                    
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    
                    [Global showTextHudSub:@"连接失败" view:self.view];
                }
                
            }];
            
        }
    }

}


-(void)adds:(UIButton*)sender{
    
    
    
    [tianjiashanping setTitle:[NSString stringWithFormat:@"%@", @""] forState:UIControlStateNormal];
    
    [tianjiashanping removeFromSuperview];
    [jiage removeFromSuperview];
    [jiageTextFied removeFromSuperview];
    [kucun removeFromSuperview];
    [kucunTextFied removeFromSuperview];
    
   jiageTextFied.text=@"";
   kucunTextFied.text=@"";
    
    view33.frame=CGRectMake(0, 90, ScreenWidth, 10);
    
    view22.frame=CGRectMake(0, self.collectionView.bottom+10, ScreenWidth, 45);
    view1.frame=CGRectMake(0, self.collectionView.bottom+10+45, ScreenWidth, 100);
    
    myscrollView.frame=CGRectMake(0, 0, ScreenWidth, view1.bottom);
    myscrollView.contentSize = CGSizeMake(ScreenWidth,view1.bottom );
    _table.tableHeaderView=myscrollView;

    biaoqianview.frame=CGRectMake(0, -10, ScreenWidth, 400);
    
    UIButton* button=(UIButton * )sender;
    addguigeCell* cell=(addguigeCell* )button.superview.superview;
    cell.shuzi= cell.shuzi;
    
    [specName addObject:[NSString stringWithFormat:@"%@",  @""]];
    [specPrice addObject:[NSString stringWithFormat:@"%@",  @""]];
//   [specInv addObject:[NSString stringWithFormat:@"%@",  @""]];
    [_table reloadData];


}
-(void)add:(UIButton*)sender{

    
    [tianjiashanping setTitle:[NSString stringWithFormat:@"%@", @""] forState:UIControlStateNormal];
    
    [tianjiashanping removeFromSuperview];
    
    
    
    UIButton* button=(UIButton * )sender;
    addguigeCell* cell=(addguigeCell* )button.superview.superview;
    cell.shuzi= cell.shuzi;

    
if ([cell.text.text length]>0&&[cell.text1.text length]>0) {
    [specName removeObjectAtIndex:cell.shuzi.intValue];
    [specPrice removeObjectAtIndex:cell.shuzi.intValue];
//  [specInv removeObjectAtIndex:cell.shuzi.intValue];
    
    [specName addObject:[NSString stringWithFormat:@"%@",  cell.text.text]];
    [specPrice addObject:[NSString stringWithFormat:@"%@",  cell.text1.text]];
//  [specInv addObject:[NSString stringWithFormat:@"%@",  cell.text2.text]];
    
    [specName addObject:[NSString stringWithFormat:@"%@",  @""]];
    [specPrice addObject:[NSString stringWithFormat:@"%@",  @""]];
//  [specInv addObject:[NSString stringWithFormat:@"%@",  @""]];
    
    [_table reloadData];
   

    NSLog(@"%@",specName);


}else{
    
        [self showAlertMessage:@"请选填上面的规格"];
    
    
}

    


    
}


- (void)textFieldDidEndEditing:(UITextField *)textField
{
    
   
    if (textField.tag==10) {
        

    addguigeCell *cell  = (addguigeCell *)[[textField superview] superview];
    NSIndexPath *indexPath = [_table indexPathForCell:cell];
        
    [specName replaceObjectAtIndex:indexPath.row withObject:cell.text.text];

    
    }
    if (textField.tag==11) {
        
      
        addguigeCell *cell  = (addguigeCell *)[[textField superview] superview];
        NSIndexPath *indexPath = [_table indexPathForCell:cell];
      
         [specPrice replaceObjectAtIndex:indexPath.row withObject:cell.text1.text];
        
       
        
    }


    
}
- (void)customLayout
{
    
    int numberOfLines = (int)ceil([self collectionView:self.collectionView numberOfItemsInSection:0] / 4.0);
    
    CGRect frame = self.collectionView.frame;
    frame.size.height = numberOfLines *collectionCellHeight + (numberOfLines - 1) * 5 + 15*2;
    self.collectionView.frame = frame;
   
   
    
    if (specName.count==0) {
         view22.frame=CGRectMake(0, self.collectionView.bottom+10, ScreenWidth, 45);
         view1.frame=CGRectMake(0, self.collectionView.bottom+10+45, ScreenWidth, 180-45);
      }else{
        view22.frame=CGRectMake(0, self.collectionView.bottom+10, ScreenWidth, 45);
        view1.frame=CGRectMake(0, self.collectionView.bottom+10+45, ScreenWidth, 100);
      }
   
    
    myscrollView.frame=CGRectMake(0, 0, ScreenWidth, view1.bottom);
    myscrollView.contentSize = CGSizeMake(ScreenWidth,view1.bottom );
    _table.tableHeaderView=myscrollView;
   

}


#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [specName count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    
    addguigeCell* cell = (addguigeCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        NSArray* nib = [[NSBundle mainBundle] loadNibNamed:@"addguigeCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }
     cell.text.text=specName[indexPath.row];
     cell.text1.text=specPrice[indexPath.row];
//   cell.text2.text=specInv[indexPath.row];
     cell.selectionStyle = UITableViewCellSelectionStyleNone;
    [cell.shanchu addTarget:self action:@selector(shanchu:) forControlEvents:UIControlEventTouchUpInside];
    cell.shanchu.tag=indexPath.row;
    cell.shuzi=[NSString stringWithFormat:@"%ld" ,indexPath.row];
    
         cell.text.inputAccessoryView = myToolBar;
         cell.text1.inputAccessoryView = myToolBar;
//       cell.text2.inputAccessoryView = myToolBar;
    
    if (specName.count !=indexPath.row+1) {
        UILabel *lineLabel1=[[UILabel alloc] initWithFrame:CGRectMake(15, 90-0.45, ScreenWidth-30, 0.45)];
        lineLabel1.backgroundColor=zuiqianhuicolor;
        [cell.contentView addSubview:lineLabel1];
  
    }
    
    if (specName.count ==indexPath.row+1) {
        UILabel *lineLabel1=[[UILabel alloc] initWithFrame:CGRectMake(0, 100-0.45, ScreenWidth, 0.45)];
        lineLabel1.backgroundColor=zuiqianhuicolor;
        
        UIButton* tianjiashanping1=[[UIButton alloc]initWithFrame:CGRectMake(0, 100, ScreenWidth,45)];
        [tianjiashanping1 setTitle:[NSString stringWithFormat:@"     %@", @"＋   添加商品规格"] forState:UIControlStateNormal];

        NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"    %@", @"＋   添加商品规格"]];
        
        [AttributedStr addAttribute:NSFontAttributeName
         
                              value:[UIFont systemFontOfSize:16.0]
         
                              range:NSMakeRange(0, 2)];
        
        [AttributedStr addAttribute:NSForegroundColorAttributeName
         
                              value:hongsecolor
         
                              range:NSMakeRange(0, 7)];
        
        
        tianjiashanping1.titleLabel.attributedText = AttributedStr;
        tianjiashanping1.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
        tianjiashanping1.titleLabel.font=[UIFont systemFontOfSize:conten14fot];
        [tianjiashanping1 addTarget:self action:@selector(add:) forControlEvents:UIControlEventTouchUpInside];
        tianjiashanping1.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        tianjiashanping1.layer.borderWidth = 0.35;
        tianjiashanping1.layer.borderColor = qianhuicolor.CGColor;
         tianjiashanping1.backgroundColor=[UIColor whiteColor];
        [tianjiashanping1 setTitleColor:luseColor forState:UIControlStateNormal];
        [cell.contentView addSubview:tianjiashanping1];
    }
    
    return cell;
}

- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (specName.count ==indexPath.row+1) {
    
    return  155;
    
    }
    return  100;
}

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
 
//    NSArray *indexPathsForVisibleRows = [_table indexPathsForVisibleRows];
//    NSMutableSet *sectionSet = [NSMutableSet set];
//    
//    for ( NSIndexPath *indexPath in indexPathsForVisibleRows ) {
//        [sectionSet addObject:[NSNumber numberWithInt:0]];
//    }
//    NSLog(@"sectionSet %@",sectionSet);
//    // sectionSet {(13, 11, 9, 10, 12 )}
 
}
//从指定索引移除

-(void)shanchu:(UIButton*)sender{
   
    
    [tv resignFirstResponder];
    [jiageTextFied resignFirstResponder];
    [leibieTextFied resignFirstResponder];
    [mingchengTextFied resignFirstResponder];
    [kucunTextFied resignFirstResponder];

    
    UIButton* button=(UIButton * )sender;
    addguigeCell* cell=(addguigeCell* )button.superview.superview;
    cell.shuzi= cell.shuzi;
    
    [cell.text resignFirstResponder];
    [cell.text1 resignFirstResponder];
//  [cell.text2 resignFirstResponder];
    
     [specName removeObjectAtIndex:sender.tag];//从指定索引移除
     [specPrice removeObjectAtIndex:sender.tag];//从指定索引移除
//   [specInv removeObjectAtIndex:sender.tag];//从指定索引移除

    
    [_table reloadData];
    
    
    if (specName.count==0) {
        
        [view33 removeFromSuperview];
        jiage=[[UILabel alloc]initWithFrame:CGRectMake(20, 90, 70,45)];
        jiage.text=[NSString stringWithFormat:@"%@", @"价格"];
        jiage.font=[UIFont systemFontOfSize:conten14fot];
        jiage.textColor=[UIColor blackColor];
        [view1 addSubview:jiage];
        jiageTextFied=[[UITextField alloc]initWithFrame:CGRectMake(70,  90, ScreenWidth*550/750,  45)];
        jiageTextFied.keyboardType = UIKeyboardTypeDecimalPad;
        jiageTextFied.font = [UIFont systemFontOfSize: conten14fot];
        jiageTextFied.textColor=[UIColor blackColor];
        jiageTextFied.autocapitalizationType = UITextAutocapitalizationTypeSentences;
        jiageTextFied.tag=7;
        jiageTextFied.placeholder = @"请输入价格"; //默认显示的字
        [jiageTextFied setUserInteractionEnabled:YES];
        jiageTextFied.delegate = self;
        jiageTextFied.clearButtonMode = UITextFieldViewModeWhileEditing;
        [view1 addSubview:jiageTextFied];
        jiageTextFied.inputAccessoryView = myToolBar;
        

        
        view33=[[UIView alloc]initWithFrame:CGRectMake(0, 180-45, ScreenWidth, 10)];
        view33.backgroundColor=zuiqianhuicolor;
        [view1 addSubview:view33];
        view1.frame=CGRectMake(0,self.collectionView.bottom+10+45, ScreenWidth, 190-45);
        myscrollView.frame=CGRectMake(0, 0, ScreenWidth, view1.bottom);
        myscrollView.contentSize = CGSizeMake(ScreenWidth,view1.bottom );
        _table.tableHeaderView=myscrollView;
        
        biaoqianview.frame=CGRectMake(0, 45, ScreenWidth, 400);
        
        tianjiashanping=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth,45)];
        
        
        [tianjiashanping setTitle:[NSString stringWithFormat:@"     %@", @"＋   添加商品规格"] forState:UIControlStateNormal];
        NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"    %@", @"＋  添加商品规格"]];
        
        [AttributedStr addAttribute:NSFontAttributeName
         
                              value:[UIFont systemFontOfSize:16.0]
         
                              range:NSMakeRange(0, 2)];
        
        [AttributedStr addAttribute:NSForegroundColorAttributeName
         
                              value:hongsecolor
         
                              range:NSMakeRange(0, 7)];
        
        
        tianjiashanping.titleLabel.attributedText = AttributedStr;
        tianjiashanping.titleLabel.font=[UIFont systemFontOfSize:conten14fot];
        [tianjiashanping addTarget:self action:@selector(adds:) forControlEvents:UIControlEventTouchUpInside];
        [tianjiashanping setTitleColor:luseColor forState:UIControlStateNormal];
        tianjiashanping.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
        tianjiashanping.layer.borderWidth = 0.30;
        tianjiashanping.layer.borderColor = qianhuicolor.CGColor;
        
        [guigeview addSubview:tianjiashanping];
        [_table reloadData];
    }
    
    
}









-(void)leibieBtn:(UIButton*)sender{
//      commdity.sat=@"";
    
       PlatformProductTypeListViewController *detailViewController = [[PlatformProductTypeListViewController alloc] init];
       [self.navigationController pushViewController:detailViewController animated:YES];
}

-(void)ItemCodebut:(UIButton*)sender{

    saveAccount=! saveAccount;

    if (!saveAccount) {
        if (selectFeatureCodeArray.count>0) {
            [sender setTitleColor:zhonghuiColor forState:0];
            CGColorSpaceRef colorSpace2 = CGColorSpaceCreateDeviceRGB();
            CGColorRef colorref2 = CGColorCreate(colorSpace2,(CGFloat[]){153/255.0,153/255.0, 153/255.0, 1.0   });
            sender.backgroundColor=[UIColor whiteColor];
            [sender.layer setBorderColor:colorref2];//边框颜色
            for (int i=0; i<selectFeatureCodeArray.count; i++) {
                
                NSString *codeStr = [selectFeatureCodeArray objectAtIndex:i];
               
                NSString* leishi=[NSString stringWithFormat:@"%@", [[arrrs objectAtIndex:sender.tag-1]objectForKey:@"code"]];
if (codeStr.intValue == leishi.intValue ) {
                    
                    [selectFeatureCodeArray removeObjectAtIndex:i];//从指定索引移除
                }
            }
            NSLog(@"---------%@",selectFeatureCodeArray);
        }
          
    }
    else
    {
        
        [sender setTitleColor:huangtitleColor forState:0];
        CGColorSpaceRef colorSpace2 = CGColorSpaceCreateDeviceRGB();
        CGColorRef colorref2 = CGColorCreate(colorSpace2,(CGFloat[]){209/255.0,170/255.0, 56/255.0, 1.0   });
        sender.backgroundColor=[UIColor colorWithRed:255/255.0 green:255/255.0 blue:234/255.0 alpha:1];
        [sender.layer setBorderColor:colorref2];//边框颜色
        
        [selectFeatureCodeArray addObject:[[arrrs objectAtIndex:sender.tag-1]objectForKey:@"code"]];
        NSLog(@"---------%@",selectFeatureCodeArray);
      
        
    }
    
}
- (void)textFieldDidBeginEditing:(UITextField *)textField{
    
    if (textField.tag == 7)
    { [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
        _table .frame =CGRectMake(0, -50, ScreenWidth, ScreenHeight);
        [UIView commitAnimations];
        
        
    }if (textField.tag ==6)
    { [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
        _table .frame =CGRectMake(0, -50, ScreenWidth, ScreenHeight);
        [UIView commitAnimations];
        
    }
    if (textField.tag ==8)
    { [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
        _table .frame =CGRectMake(0, -150, ScreenWidth, ScreenHeight);
        [UIView commitAnimations];
        
    }
}
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{
    
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    _table .frame =CGRectMake(0, -200, ScreenWidth, ScreenHeight);
    [UIView commitAnimations];
    
    return self;
}

-(void)textViewDidChange:(UITextView *)textView
{
    //self.examineText =  textView.text;
    
    
    if (textView.text.length == 0) {
        [imagess removeFromSuperview];
        
        imagess=[[UIImageView alloc]initWithFrame:CGRectMake(10, 7, 51/3, 51/3)];
        imagess.image=[UIImage imageNamed:@"_0000_xingxifankui.png"];
        [tv addSubview:imagess];
        label.text = @"详情描述";
        
    }else{
        [imagess removeFromSuperview];
        label.text = @"";
    }
}




- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return imageArray.count+1;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * string = @"cell";
    webCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:string forIndexPath:indexPath];
    
    
    if (indexPath.row == imageArray.count) {
        cell.imgView.image = [UIImage imageNamed:@"tianjiatupain"];
    }else{
        cell.imgView.image = imageArray[indexPath.row];
    }
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{

    if (indexPath.item == imageArray.count)
    {
        UIActionSheet* actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"拍照", @"从相册选择", nil];
        [actionSheet showInView:self.view];
    }
    else
    {
        UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"确定删除" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
        alertView.tag = indexPath.row;
        [alertView show];
    }
    
    [collectionView reloadData];
 
}
#pragma mark UIActionSheetDelegate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 0) {
        // 拍照
        if ([self isCameraAvailable] && [self doesCameraSupportTakingPhotos]) {
            UIImagePickerController *controller = [[UIImagePickerController alloc] init];
            controller.sourceType = UIImagePickerControllerSourceTypeCamera;
            controller.cameraDevice = UIImagePickerControllerCameraDeviceRear;
            NSMutableArray *mediaTypes = [[NSMutableArray alloc] init];
            [mediaTypes addObject:(__bridge NSString *)kUTTypeImage];
            controller.mediaTypes = mediaTypes;
            controller.delegate = self;
            controller.allowsEditing = YES;
            //            controller.showsCameraControls=true;
            [self presentViewController:controller
                               animated:YES
                             completion:^(void){
                                 NSLog(@"Picker View Controller is presented");
                             }];
        }
        
    } else if (buttonIndex == 1) {
        // 从相册中选取
        if ([self isPhotoLibraryAvailable]) {
            UIImagePickerController *controller = [[UIImagePickerController alloc] init];
            controller.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            NSMutableArray *mediaTypes = [[NSMutableArray alloc] init];
            [mediaTypes addObject:(__bridge NSString *)kUTTypeImage];
            controller.mediaTypes = mediaTypes;
            controller.delegate = self;
            controller.allowsEditing = YES;
            //            controller.showsCameraControls=NO;
            [self presentViewController:controller
                               animated:YES
                             completion:^(void){
                                 NSLog(@"Picker View Controller is presented");
                             }];
        }
    }
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    
    if (buttonIndex == 1)
    {
        
        [imageArray removeObjectAtIndex:alertView.tag];
        [self.collectionView reloadData];
        [self customLayout];
        
    }
}

//图像选取器的委托方法，选完图片后回调该方法
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage* image = [info valueForKey:UIImagePickerControllerEditedImage];
    if (image != nil)
    {
        
        
        [imageArray addObject:image];
        [self.collectionView reloadData];
        [self customLayout];
        
    }
    [picker dismissViewControllerAnimated:YES completion:nil];
}


-(void)OnTapDone{
    
    [tv resignFirstResponder];
    [jiageTextFied resignFirstResponder];
    [leibieTextFied resignFirstResponder];
    [mingchengTextFied resignFirstResponder];
    [kucunTextFied resignFirstResponder];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    _table .frame =CGRectMake(0, 0, ScreenWidth, ScreenHeight);
    [UIView commitAnimations];
    [_table reloadData];

    
}


- (void)showAlertWait
{
    alt = [[UIAlertView alloc] initWithTitle:@"网络不稳定 ！" message:@"请确认网络" delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
    
}

- (void)showAlertMessage:(NSString *)msg
{
    alt = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:msg delegate:nil cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
}
- (void)hideAlert
{
    if (alt != nil)
    {
        [alt dismissWithClickedButtonIndex:0 animated:YES];
        alt = nil;
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(NSString * )getSaveKey {
    /**
     *	@brief	方式1 由开发者生成saveKey
     */
    NSDate *d = [NSDate date];
    return [NSString stringWithFormat:@"/%d/%d/%.0f.png",[self getYear:d],[self getMonth:d],[[NSDate date] timeIntervalSince1970]];
    
    /**
     *	@brief	方式2 由服务器生成saveKey
     */
    //    return [NSString stringWithFormat:@"/{year}/{mon}/{filename}{.suffix}"];
    
    /**
     *	@brief	更多方式 参阅 http://wiki.upyun.com/index.php?title=Policy_%E5%86%85%E5%AE%B9%E8%AF%A6%E8%A7%A3
     */
    
}


- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
    [picker dismissViewControllerAnimated:YES completion:^(){
    }];
}

#pragma mark - UINavigationControllerDelegate
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
}

- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    
}

#pragma mark camera utility
- (BOOL) isCameraAvailable{
    return [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
}

- (BOOL) isRearCameraAvailable{
    return [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear];
}

- (BOOL) isFrontCameraAvailable {
    return nil;
}

- (BOOL) doesCameraSupportTakingPhotos {
    return [self cameraSupportsMedia:(__bridge NSString *)kUTTypeImage sourceType:UIImagePickerControllerSourceTypeCamera];
}

- (BOOL) isPhotoLibraryAvailable{
    return [UIImagePickerController isSourceTypeAvailable:
            UIImagePickerControllerSourceTypePhotoLibrary];
}
- (BOOL) canUserPickVideosFromPhotoLibrary{
    return [self
            cameraSupportsMedia:(__bridge NSString *)kUTTypeMovie sourceType:UIImagePickerControllerSourceTypePhotoLibrary];
}
- (BOOL) canUserPickPhotosFromPhotoLibrary{
    return [self
            cameraSupportsMedia:(__bridge NSString *)kUTTypeImage sourceType:UIImagePickerControllerSourceTypePhotoLibrary];
}

- (BOOL) cameraSupportsMedia:(NSString *)paramMediaType sourceType:(UIImagePickerControllerSourceType)paramSourceType{
    __block BOOL result = NO;
    if ([paramMediaType length] == 0) {
        return NO;
    }
    NSArray *availableMediaTypes = [UIImagePickerController availableMediaTypesForSourceType:paramSourceType];
    [availableMediaTypes enumerateObjectsUsingBlock: ^(id obj, NSUInteger idx, BOOL *stop) {
        NSString *mediaType = (NSString *)obj;
        if ([mediaType isEqualToString:paramMediaType]){
            result = YES;
            *stop= YES;
        }
    }];
    return result;
}
#define ORIGINAL_MAX_WIDTH 320
#pragma mark image scale utility
- (UIImage *)imageByScalingToMaxSize:(UIImage *)sourceImage {
    if (sourceImage.size.width < ORIGINAL_MAX_WIDTH) return sourceImage;
    CGFloat btWidth = 0.0f;
    CGFloat btHeight = 0.0f;
    if (sourceImage.size.width > sourceImage.size.height) {
        btHeight = ORIGINAL_MAX_WIDTH;
        btWidth = sourceImage.size.width * (ORIGINAL_MAX_WIDTH / sourceImage.size.height);
    } else {
        btWidth = ORIGINAL_MAX_WIDTH;
        btHeight = sourceImage.size.height * (ORIGINAL_MAX_WIDTH / sourceImage.size.width);
    }
    CGSize targetSize = CGSizeMake(btWidth, btHeight);
    return [self imageByScalingAndCroppingForSourceImage:sourceImage targetSize:targetSize];
}

- (UIImage *)imageByScalingAndCroppingForSourceImage:(UIImage *)sourceImage targetSize:(CGSize)targetSize {
    
    UIImage *newImage = nil;
    CGSize imageSize = sourceImage.size;
    CGFloat width = imageSize.width;
    CGFloat height = imageSize.height;
    CGFloat targetWidth = targetSize.width;
    CGFloat targetHeight = targetSize.height;
    CGFloat scaleFactor = 0.0;
    CGFloat scaledWidth = targetWidth;
    CGFloat scaledHeight = targetHeight;
    CGPoint thumbnailPoint = CGPointMake(0.0,0.0);
    
    if (CGSizeEqualToSize(imageSize, targetSize) == NO)
    {
        CGFloat widthFactor = targetWidth / width;
        CGFloat heightFactor = targetHeight / height;
        
        if (widthFactor > heightFactor)
            scaleFactor = widthFactor; // scale to fit height
        else
            scaleFactor = heightFactor; // scale to fit width
        scaledWidth= width * scaleFactor;
        scaledHeight = height * scaleFactor;
        
        // center the image
        if (widthFactor > heightFactor)
        {
            thumbnailPoint.y = (targetHeight - scaledHeight) * 0.5;
        }
        else if (widthFactor < heightFactor)
        {
            thumbnailPoint.x = (targetWidth - scaledWidth) * 0.5;
        }
    }
    
    UIGraphicsBeginImageContext(targetSize); // this will crop
    
    CGRect thumbnailRect = CGRectZero;
    thumbnailRect.origin = thumbnailPoint;
    thumbnailRect.size.width= scaledWidth;
    thumbnailRect.size.height = scaledHeight;
    
    [sourceImage drawInRect:thumbnailRect];
    
    newImage = UIGraphicsGetImageFromCurrentImageContext();
    if(newImage == nil)
        NSLog(@"could not scale image");
    
    //pop the context to get back to the default
    UIGraphicsEndImageContext();
    return newImage;
}


- (int)getYear:(NSDate *) date{
    NSDateFormatter *formatter =[[NSDateFormatter alloc] init];
    [formatter setTimeStyle:NSDateFormatterMediumStyle];
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    NSInteger unitFlags = NSYearCalendarUnit;
    NSDateComponents *comps = [calendar components:unitFlags fromDate:date];
    int year=[comps year];
    return year;
}

- (int)getMonth:(NSDate *) date{
    NSDateFormatter *formatter =[[NSDateFormatter alloc] init];
    [formatter setTimeStyle:NSDateFormatterMediumStyle];
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    NSInteger unitFlags = NSMonthCalendarUnit;
    NSDateComponents *comps = [calendar components:unitFlags fromDate:date];
    int month = [comps month];
    return month;
}

@end

